import random
from datetime import datetime

if __name__ == '__main__':

    name = '/home/lpk/data/FB86m/train.txt'
    
    starttime = datetime.now()

    with open(name, 'r', encoding='utf-8') as f:
        lines = f.readlines()#获取所有行
        sum = 0
        list = []
        for line in lines:#第i行
            #找到第一个空格
            list.append(line)
            # for j in range(len(line)):
            #     if line[j].isspace() == True:
            #         a = line[:j]
            #         # if a not in list:
            #         list.append(a)
            #         sum += 1
        f.close()
    midtime = datetime.now()
    print ("The running time for load file is " + str((midtime - starttime).seconds) + " seconds")

    tmptime0 = datetime.now()

    with open('/home/lpk/data/split/dev1.txt', 'w', encoding='utf-8') as g:
        a = random.sample(list, 38090956)#随机抽取
        for i in a:
            g.write(i)
        g.close()

    tmptime1 = datetime.now()
    print ("The running time for generate dev1 is " + str((tmptime1 - tmptime0).seconds) + " seconds")
    tmptime0 = datetime.now()

    with open('/home/lpk/data/split/dev2.txt', 'w', encoding='utf-8') as g:
        a = random.sample(list, 38090956)#随机抽取
        for i in a:
            g.write(i)
        g.close()

    tmptime1 = datetime.now()
    print ("The running time for generate dev2 is " + str((tmptime1 - tmptime0).seconds) + " seconds")
    tmptime0 = datetime.now()
    
        
    with open('/home/lpk/data/split/dev3.txt', 'w', encoding='utf-8') as g:
        a = random.sample(list, 38090956)#随机抽取
        for i in a:
            g.write(i)
        g.close()

    tmptime1 = datetime.now()
    print ("The running time for generate dev3 is " + str((tmptime1 - tmptime0).seconds) + " seconds")
    tmptime0 = datetime.now()


    with open('/home/lpk/data/split/dev4.txt', 'w', encoding='utf-8') as g:
        a = random.sample(list, 38090956)#随机抽取
        for i in a:
            g.write(i)
        g.close()
    
    tmptime1 = datetime.now()
    print ("The running time for generate dev4 is " + str((tmptime1 - tmptime0).seconds) + " seconds")
    tmptime0 = datetime.now()


    with open('/home/lpk/data/split/dev5.txt', 'w', encoding='utf-8') as g:
        a = random.sample(list, 38090956)#随机抽取
        for i in a:
            g.write(i)
        g.close()

    tmptime1 = datetime.now()
    print ("The running time for generate dev5 is " + str((tmptime1 - tmptime0).seconds) + " seconds")
    tmptime0 = datetime.now()


    with open('/home/lpk/data/split/dev6.txt', 'w', encoding='utf-8') as g:
        a = random.sample(list, 38090956)#随机抽取
        for i in a:
            g.write(i)
        g.close()

    tmptime1 = datetime.now()
    print ("The running time for generate dev6 is " + str((tmptime1 - tmptime0).seconds) + " seconds")
    tmptime0 = datetime.now()
    

    with open('/home/lpk/data/split/dev7.txt', 'w', encoding='utf-8') as g:
        a = random.sample(list, 38090956)#随机抽取
        for i in a:
            g.write(i)
        g.close()

    tmptime1 = datetime.now()
    print ("The running time for generate dev7 is " + str((tmptime1 - tmptime0).seconds) + " seconds")
    tmptime0 = datetime.now()


    with open('/home/lpk/data/split/dev8.txt', 'w', encoding='utf-8') as g:
        a = random.sample(list, 38090958)#随机抽取
        for i in a:
            g.write(i)
        g.close()

    tmptime1 = datetime.now()
    print ("The running time for generate dev8 is " + str((tmptime1 - tmptime0).seconds) + " seconds")
    tmptime0 = datetime.now()

    endtime = datetime.now()
    print ("The running time for random partition file is " + str((endtime - midtime).seconds) + " seconds")
    print ("The total running time is " + str((endtime - starttime).seconds) + " seconds")

